// pages/user/shop-order-list/work-order.js
const app = getApp()
const user  = require('../../../api/user')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    my_avatar: app.getUser().avatar,
    kefu_avatar: 'https://o.rjkj7.com/data/upload/xcximages/avatar_default.png',
    workId: '',
    comment: '',
    workOrder: null,
    comments: [],
    STATUS_TEXT: {
      '-1': '工单关闭',
      0: '未处理',
      1: '移交财务处理',
      2: '财务打款'
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const workId = options.id
    this.setData({workId})
    this.initData()
  },

  initData() {
    app.requestUrl({url:user.WORKORDER_DETAIL, data:{id: this.data.workId}}).then(res => {
        this.setData({
          workOrder: res.data.data,
          comments: res.data.comment
        })
        
    });
  },

  onChange(e) {
    this.setData({
      comment: e.detail
    })
  },

  addComment() {
      const comment = {
          workId: this.data.workOrder.id,
          mid: this.data.workOrder.mid,
          remark: this.data.comment
      }
      app.requestUrl({url:user.WORKORDER_COMMENT, data:comment}).then(res => {
          if (res.data.data > 0) {
              this.setData({
                comments: this.data.comments.push(comment),
                comment: ''
              })
              // this.comments.push(comment);
              // this.comment = '';
          }
      });
  },
  preview(image) {
      ImagePreview([image]);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})